﻿package mortal.game.view.petNew
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.mount.panel.*;
    import mortal.game.view.petNew.view.*;

    public class NewPetModule extends GSprite
    {
        protected var _winTitleName:String;
        private var _dicIndexClass:Dictionary;
        private var _dicIndexPanel:Dictionary;
        private var _petInfo:PetInfoPanel;
        private var _currentPanel:NewPetPanelBase;
        private var _isShowBlessWin:Boolean = true;

        public function NewPetModule()
        {
            this._dicIndexClass = new Dictionary();
            this._dicIndexPanel = new Dictionary();
            setSize(781, 550);
            this._winTitleName = "" + Language.getString(71774);
            return;
        }// end function

        public function get winTitleName() : String
        {
            return this._winTitleName;
        }// end function

        protected function onTabBarChange(event:Event = null) : void
        {
            var _loc_2:NewPetPanelBase = null;
            _loc_2 = this._dicIndexPanel[0] as NewPetPanelBase;
            if (_loc_2 != this._currentPanel || _loc_2 == null)
            {
                if (this._currentPanel)
                {
                    this._currentPanel.dispose(false);
                }
                if (!_loc_2)
                {
                    _loc_2 = UICompomentPool.getUICompoment(this._dicIndexClass[0], GameController.playerSystem.view as Window);
                }
                this.addChild(_loc_2);
                _loc_2.x = 0;
                _loc_2.y = 0;
                this._currentPanel = _loc_2;
                this._currentPanel.updateMsg(Cache.instance.newPet.pet);
            }
            return;
        }// end function

        protected function onMouseDownHandler(event:MouseEvent) : void
        {
            if (PetActivityPanel.hasInstance() && !PetActivityPanel.instance.isHide)
            {
                PetActivityPanel.instance.layer.setTop(PetActivityPanel.instance);
            }
            Global.stage.addEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMoveHandler);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            return;
        }// end function

        public function updatePet() : void
        {
            if (this._currentPanel)
            {
                this._currentPanel.updateMsg(Cache.instance.newPet.pet);
            }
            return;
        }// end function

        public function updateMountSelect() : void
        {
            if (this._currentPanel && this._currentPanel is PetInfoPanel)
            {
                (this._currentPanel as PetInfoPanel).updateMountSelect();
            }
            return;
        }// end function

        public function updateVip() : void
        {
            if (this._currentPanel && this._currentPanel is PetInfoPanel)
            {
                (this._currentPanel as PetInfoPanel).updateVip();
            }
            return;
        }// end function

        public function hide() : Boolean
        {
            var _loc_1:* = Cache.instance.newPet.pet;
            var _loc_2:* = MountConfig.instance.getFashionInfoByCode(EAdvanceComponentType._EAdvanceComponentTypePet, _loc_1.code);
            if (!BlessClearWin.winOpenRecortDic["" + Language.getString(71763)] && _loc_2.blessClear && _loc_1.bless > 0)
            {
            }
            else
            {
                this.callBack(BlessClearWin.BlessBtnTypeCacel);
                return false;
            }
            return false;
        }// end function

        private function callBack(param1:int) : void
        {
            if (param1 == BlessClearWin.BlessBtnTypeCacel)
            {
                this._isShowBlessWin = false;
            }
            return;
        }// end function

        private function onMouseMoveHandler(event:MouseEvent) : void
        {
            if (PetActivityPanel.hasInstance() && !PetActivityPanel.instance.isHide)
            {
                PetActivityPanel.instance.x = this.x + this.width + 5;
                PetActivityPanel.instance.y = this.y + 15;
            }
            return;
        }// end function

        private function onMouseUpHandler(event:MouseEvent) : void
        {
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            Global.stage.removeEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMoveHandler);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._dicIndexClass[0] = PetInfoPanel;
            this._dicIndexPanel[0] = this._petInfo;
            this.onTabBarChange();
            this.configEventListener(MouseEvent.MOUSE_DOWN, this.onMouseDownHandler);
            return;
        }// end function

        private function onRecCompl() : void
        {
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this._currentPanel)
            {
                this._currentPanel.dispose(param1);
            }
            this._currentPanel = null;
            this.hide();
            return;
        }// end function

        public function updateEquip() : void
        {
            if (this._currentPanel)
            {
                (this._currentPanel as PetInfoPanel).updatePetEquip();
            }
            return;
        }// end function

        public function updatePetItems() : void
        {
            if (this._currentPanel)
            {
                (this._currentPanel as PetInfoPanel).updatePetItems();
            }
            return;
        }// end function

        public function showBtnFilter() : void
        {
            if (this._currentPanel)
            {
                (this._currentPanel as PetInfoPanel).showBtnFilter();
            }
            return;
        }// end function

        public function shapeCardStatUpdate(param1:Boolean) : void
        {
            if (this._currentPanel is PetInfoPanel)
            {
                (this._currentPanel as PetInfoPanel).shapeCardStatUpdate();
            }
            return;
        }// end function

    }
}
